let ctx=wx.createCanvasContext('myCanvas')
Page({
    data:{
        mosaic:true,
        imagePath:''
    },
    open(){
        wx.chooseImage({
          count: 1,
        }).then(res=>{
            console.log(res)
            let file=res.tempFilePaths[0]
            ctx.drawImage(file,0,0,400,300)
            ctx.draw()
        })
    },
    move(e){
        console.log(e)
        if(this.data.mosaic){
            ctx.setFillStyle('black')
            ctx.fillRect(e.touches[0].x,e.touches[0].y,10,10)
            ctx.fillRect(e.touches[0].x+10,e.touches[0].y+10,10,10)
            ctx.setFillStyle('pink')
            ctx.fillRect(e.touches[0].x+10,e.touches[0].y,10,10)
            ctx.fillRect(e.touches[0].x,e.touches[0].y+10,10,10)
            ctx.draw(true)
        }else{
            ctx.clearRect(e.touches[0].x,e.touches[0].y,20,20)
            ctx.draw(true)
        }
    },
    clear(){
        this.setData({
            mosaic:false
        })
    },
    mosaic(){
        this.setData({
            mosaic:true
        })
    },
    save(){
        wx.canvasToTempFilePath({
          canvasId: myCanvas,
        }).then(res=>{
            console.log(res)
            this.setData({
                imagePath:res.tempFilePath
            })
        })
    },
    seal(){
        ctx.setFillStyle('red')
        ctx.setFontSize(40)
        ctx.fillText('07201043吴晓丹',38,200)
        ctx.draw(true)
    }
})